$(document).ready(function() {

});
button_query_onclick = function() {
	efgrid.submitInqu("ef_grid_r", "ZM", "ZMCK40", "query");
};
/*
  点击新增按钮后调用后台的service
*/
button_insert_onclick = function() {
	var grid = isSelected("ef_grid_r");
	if (grid == 0)
		return;
	var rows = grid.getCheckedRows();
	var date1;
	var date2;
	for (var i = 0; i < rows.length; i++) {
		date1 = grid.getCellValueByColumnName(rows[i], "fdBeginDate");
		date2 = grid.getCellValueByColumnName(rows[i], "fdEndDate");
		if (date1 > date2) {
			EFAlert("结束日期不能小于起始日期");
			return;
		}
	}
	efgrid.submitForm("ef_grid_r", "ZM", "ZMCK40", "insert", true);
};
button_update_onclick = function() {
	var grid = isSelected("ef_grid_r");
	if (grid == 0)
		return;
	var rows = grid.getCheckedRows();
	var date1;
	var date2;
	for (var i = 0; i < rows.length; i++) {
		date1 = grid.getCellValueByColumnName(rows[i], "fdBeginDate");
		date2 = grid.getCellValueByColumnName(rows[i], "fdEndDate");
		if (date1 > date2) {
			EFAlert("结束日期不能小于起始日期");
			return;
		}
	}
	efgrid.submitForm("ef_grid_r", "ZM", "ZMCK40", "update", true);
};
button_delete_onclick = function() {
	var grid = isSelected("ef_grid_r");
	if (grid == 0)
		return;

	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdStatus") != "草拟") {
			EFAlert("只能对草拟的记录进行删除！");
			return;
		}
	}

	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if (r)
			efgrid.submitForm("ef_grid_r", "ZM", "ZMCK40", "delete", true);
	});
};

// 上报
button_report_onclick = function() {
	var grid = isSelected("ef_grid_r");
	if (grid == 0)
		return;

	var rows = grid.getCheckedRows();
	if (rows.length > 1) {
		EFAlert("一次只能上报一条记录！", "警告");
		return;
	}
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdStatus") != "草拟") {
			EFAlert("只能上报草拟状态的记录！", "警告");
			return;
		}
		if (grid.getCellValueByColumnName(rows[i], "fdKeyId") == "") {
			EFAlert("该记录不存在，请先新增后再上报！", "警告");
			return;
		}
	}

	EFConfirm('确认要上报吗?', '确认框', function(r) {
		if (r)
			efgrid.submitForm("ef_grid_r", "ZM", "ZMCK40", "report", true);
	});
};
efgrid_afterAddNewRow = function(grid_id) {
	var fdCreator = $('#fdCreator').val();
	var fdCreateDepartmentId = $('#fdCreateDepartmentId').val();
	var fdMiningName = $('#fdMiningName').val();
	var day = getNowDate(); // 日

	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();
	if (grid_id == "ef_grid_r") {
		for (var i = 0; i < rows.length; i++) {
			grid.getBlockData().setCell(rows[i], "fdKeyId", "");
			grid.getBlockData().setCell(rows[i], "fdStatus", "草拟"); // 状态
			grid.getBlockData().setCell(rows[i], "fdMiningName", fdMiningName);// 矿井名称
			grid.getBlockData().setCell(rows[i], "fdReportDepartmentId", fdCreateDepartmentId);// 汇报部门
			grid.getBlockData().setCell(rows[i], "fdReportPerson", fdCreator);// 汇报人
			grid.getBlockData().setCell(rows[i], "fdCurrentDate", day);// 汇报日期
			grid.getBlockData().setCell(rows[i], "fdBeginDate", day);// 起始日期
			grid.getBlockData().setCell(rows[i], "fdEndDate", day);// 结束日期
			grid.getBlockData().setCell(rows[i], "fdXjPeople", fdCreator);// 休假人
		}
	}
};
